package hu.uniobuda.nik.openday.view;

import java.util.Random;
import java.util.Timer;
import hu.uniobuda.nik.openday.R;
import hu.uniobuda.nik.openday.utils.Config;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;

public class NIKButton extends Button {

	private Paint p;
	private Typeface tf;
	private Animation buttonInAnimation;
	Timer t;
	
	public NIKButton(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init();
	}

	public NIKButton(Context context, AttributeSet attrs) {
		super(context, attrs);
		init();
	}

	public NIKButton(Context context) {
		super(context);
		init();
	}
	
	private void init() {
		p = new Paint();		
		p.setColor(Color.parseColor("#606060"));
		p.setStyle(Style.STROKE);
		p.setStrokeWidth(1);		
		
		tf = Typeface.createFromAsset(getResources().getAssets(), Config.FONT);
		setTypeface(tf);
		
		buttonInAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.slide_in);		
		
	}
	
	@Override
	protected void onDraw(Canvas canvas) {	
		super.onDraw(canvas);
		
		canvas.drawLine(0, getHeight()-1, getWidth(), getHeight()-1, p);
	}
	Random rnd = new Random();
	@Override
	protected void onAttachedToWindow() {	
		super.onAttachedToWindow();
		setVisibility(View.INVISIBLE);
		postDelayed(new Runnable() {
			public void run() {
				setVisibility(View.VISIBLE);
				startAnimation(buttonInAnimation);
				
			}
		}, rnd.nextInt(200));
		
	}
	
	

	@Override
	public void setText(CharSequence text, BufferType type) {	
		super.setText(text.toString().toUpperCase(), type);
	}
	
}
